home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / GENCTXT.ZIP / CHAP1.TXT next >
Text File  |  1987-11-21  |  8KB  |  191 lines

  1.  
  2.                         Chapter 1 - Getting Started
  3.  
  4.  
  5.                           WHAT IS AN IDENTIFIER?
  6.  
  7.              Before you can do anything in any language, you must at
  8.         least know how to name an identifier.  An identifier is used
  9.         for  any variable, function, data definition, etc.   In  the
  10.         programming  language C, an identifier is a  combination  of
  11.         alphanumeric  characters,  the first being a letter  of  the
  12.         alphabet or an underline, and the remaining being any letter
  13.         of  the alphabet, any numeric digit, or the  underline.   In
  14.         the  case of some compilers, a dollar sign is permitted  but
  15.         not  as the first character of an identifier.  It should  be
  16.         pointed out that even though a dollar sign may be  permitted
  17.         by your C compiler, it is not used anywhere in this tutorial
  18.         since it is not in general use by C programmers, and is  not
  19.         even allowed by most compilers.  If you do not plan to write
  20.         any  portable  code, you can use it at will if you  feel  it
  21.         makes your code more readable.
  22.  
  23.              Two rules must be kept in mind when naming identifiers.
  24.  
  25.         1.   The  case  of  alphabetic  characters  is  significant.
  26.              Using  "INDEX" for a variable is not the same as  using
  27.              "index"  and  neither  of them is  the  same  as  using
  28.              "InDeX"  for a variable.   All three refer to different
  29.              variables.
  30.  
  31.         2.   As C is defined, up to 32 significant characters can be
  32.              used  and  will  be  considered  significant  by   most
  33.              compilers.   If  more than 32 are used,  they  will  be
  34.              ignored by the compiler.
  35.  
  36.                          WHAT ABOUT THE UNDERLINE?
  37.  
  38.              Even  though  the  underline can be used as part  of  a
  39.         variable  name, and adds greatly to the readability  of  the
  40.         resulting  code,  it  seems  to  be  used  very  little   by
  41.         experienced   C  programmers.   It  adds  greatly   to   the
  42.         readability  of  a  program to  use  descriptive  names  for
  43.         variables  and  it  would be to your  advantage  to  do  so.
  44.         Pascal  programmers tend to use long descriptive names,  but
  45.         most C programmers tend to use short cryptic names.  Most of
  46.         the  example programs in this tutorial use very short  names
  47.         for that reason.
  48.  
  49.              Any computer program has two entities to consider,  the
  50.         data,  and  the program.   They are highly dependent on  one
  51.         another  and  careful planning of both will lead to  a  well
  52.         planned and well written program.   Unfortunately, it is not
  53.         possible  to study either completely without a good  working
  54.         knowledge of the other.  For this reason, this tutorial will
  55.         jump  back  and forth between teaching  methods  of  program
  56.  
  57.  
  58.                                  Page 3
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.                         Chapter 1 - Getting Started
  69.  
  70.  
  71.         writing  and  methods of data  definition.    Simply  follow
  72.         along and you will have a good understanding of both.   Keep
  73.         in  mind that,  even though it seems expedient to  sometimes
  74.         jump right into the program coding,  time spent planning the
  75.         data  structures  will be well spent and the  final  program
  76.         will reflect the original planning.
  77.  
  78.                         HOW THIS TUTORIAL IS WRITTEN
  79.  
  80.              As  you go through the example programs,  you will find
  81.         that  every  program  is complete.   There  are  no  program
  82.         fragments that could be confusing.   This allows you to  see
  83.         every  requirement that is needed to use any of the features
  84.         of C as they are presented.  Some tutorials I have seen give
  85.         very few, and very complex examples.  They really serve more
  86.         to  confuse  the  student.  This tutorial  is  the  complete
  87.         opposite  because  it strives to cover each  new  aspect  of
  88.         programming  in  as  simple a  context  as  possible.   This
  89.         method,  however,  leads to a lack of knowledge in  how  the
  90.         various  parts  are  combined.  For that  reason,  the  last
  91.         chapter is devoted entirely to using the features taught  in
  92.         the  earlier  chapters. It will illustrate how  to  put  the
  93.         various features together to create a usable program.   They
  94.         are given for your study, and are not completely  explained.
  95.         Enough details of their operation are given to allow you  to
  96.         understand how they work after you have completed all of the
  97.         previous lessons.
  98.  
  99.              At this point, you should load and run FIRSTEX.C if you
  100.         have  not  yet  done  so, to see that  your  C  compiler  is
  101.         properly  loaded and operating.  If you have  any  problems,
  102.         the COMPILER.DOC file may have help for your compiler.  Even
  103.         if  it doesn't have help for your particular  compiler,  the
  104.         notes  on another compiler may be helpful for yours since  C
  105.         compilers tend to have many things in common.
  106.  
  107.                      A DISCUSSION OF SOME OF THE FILES
  108.  
  109.                                   CCL.BAT
  110.  
  111.              This  file,  which does not exist on  the  distribution
  112.         disk,  is the batch file that calls in an editor,  then  the
  113.         compiler (pass 1 and pass 2, if it exists), and finally runs
  114.         the resulting compiled program.  There are several  examples
  115.         of  batch  files which can be used  with  various  compilers
  116.         given  in  the  "COMPILER.DOC"  file  on  the   distribution
  117.         diskette.   It is up to you to type in a batch file for  use
  118.         with  your particular compiler, considering also the  method
  119.         required to call in your editor.  To use it, simply type the
  120.         batchfile  name with the desired filename.  After typing  in
  121.         your particular CCL.BAT file, try it by typing CCL  FIRSTEX.
  122.  
  123.  
  124.                                  Page 4
  125.  
  126.  
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.                         Chapter 1 - Getting Started
  135.  
  136.  
  137.         You will get the sourcefile displayed on the monitor by your
  138.         editor.   If you don't have one of the compilers  listed  in
  139.         the  "COMPILER.DOC" file, you will have to modify the  batch
  140.         file  to  accomodate your compiler.  Note that  if  you  are
  141.         using  Turbo C, you can use the Integrated  Environment  and
  142.         you will not need a batch file.  The same is true if you are
  143.         using  Microsoft Quick-C, it has its own built in  operating
  144.         environment so you will not need a batchfile.
  145.  
  146.              If you have a hard disk available, it will be up to you
  147.         to  modify the batch file to use the hard disk.   Note  that
  148.         most of the batch files have statements to erase the  object
  149.         files  and  executable files after use to prevent  the  disk
  150.         from  filling up with unecessary files after a  program  has
  151.         served its purpose.
  152.  
  153.              Even though you will have a lot of files to compile and
  154.         run, you will find that a suitable batch file will help  you
  155.         to get through the steps quickly and with little typing.
  156.  
  157.                                   LIST.EXE
  158.  
  159.              This  file will list the source files for you with line
  160.         numbers  and  filename.   To  use  it,  simply  type  "LIST"
  161.         followed by the appropriate filename.   Type LIST  FIRSTEX.C
  162.         now  for  an example.   The C source code is given later  in
  163.         Chapter 14 along with a brief description of its operation.
  164.         After you have completed your study of C, you will have  the
  165.         ability  to  read and understand the source  code  for  this
  166.         program.
  167.  
  168.                                 PRINTALL.BAT
  169.  
  170.              This is a batch file that will call the above  LIST.EXE
  171.         file  once for each of the example C programs,  printing all
  172.         of  the  files out.   If you want a hardcopy of all  of  the
  173.         files,  enter PRINTALL and watch as your printer fills about
  174.         150 sheets of paper with C programs.
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.  
  190.                                  Page 5
  191.